package com.ruoyi.wx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wx.domain.AmountLog;
import com.ruoyi.wx.service.IAmountLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户金额变化Controller
 * 
 * @author wt
 * @date 2020-12-13
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wx/amountLog" )
public class AmountLogController extends BaseController {

    private final IAmountLogService iAmountLogService;

    /**
     * 查询用户金额变化列表
     */
    @PreAuthorize("@ss.hasPermi('wx:amountLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmountLog amountLog)
    {
        startPage();
        LambdaQueryWrapper<AmountLog> lqw = Wrappers.lambdaQuery(amountLog);
        if (amountLog.getOperationType() != null){
            lqw.eq(AmountLog::getOperationType ,amountLog.getOperationType());
        }
        if (amountLog.getAmount() != null){
            lqw.eq(AmountLog::getAmount ,amountLog.getAmount());
        }
        if (StringUtils.isNotBlank(amountLog.getOrigin())){
            lqw.eq(AmountLog::getOrigin ,amountLog.getOrigin());
        }
        if (StringUtils.isNotBlank(amountLog.getCallStack())){
            lqw.eq(AmountLog::getCallStack ,amountLog.getCallStack());
        }
        if (StringUtils.isNotBlank(amountLog.getWxName())){
            lqw.like(AmountLog::getWxName ,amountLog.getWxName());
        }
        if (amountLog.getWxInfoId() != null){
            lqw.eq(AmountLog::getWxInfoId ,amountLog.getWxInfoId());
        }
        if (StringUtils.isNotBlank(amountLog.getWxId())){
            lqw.eq(AmountLog::getWxId ,amountLog.getWxId());
        }
        if (StringUtils.isNotBlank(amountLog.getToWxId())){
            lqw.eq(AmountLog::getToWxId ,amountLog.getToWxId());
        }
        if (amountLog.getBeforeOperation() != null){
            lqw.eq(AmountLog::getBeforeOperation ,amountLog.getBeforeOperation());
        }
        List<AmountLog> list = iAmountLogService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户金额变化列表
     */
    @PreAuthorize("@ss.hasPermi('wx:amountLog:export')" )
    @Log(title = "用户金额变化" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(AmountLog amountLog) {
        LambdaQueryWrapper<AmountLog> lqw = new LambdaQueryWrapper<AmountLog>(amountLog);
        List<AmountLog> list = iAmountLogService.list(lqw);
        ExcelUtil<AmountLog> util = new ExcelUtil<AmountLog>(AmountLog. class);
        return util.exportExcel(list, "amountLog" );
    }

    /**
     * 获取用户金额变化详细信息
     */
    @PreAuthorize("@ss.hasPermi('wx:amountLog:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iAmountLogService.getById(id));
    }

    /**
     * 新增用户金额变化
     */
    @PreAuthorize("@ss.hasPermi('wx:amountLog:add')" )
    @Log(title = "用户金额变化" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmountLog amountLog) {
        return toAjax(iAmountLogService.save(amountLog) ? 1 : 0);
    }

    /**
     * 修改用户金额变化
     */
    @PreAuthorize("@ss.hasPermi('wx:amountLog:edit')" )
    @Log(title = "用户金额变化" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmountLog amountLog) {
        return toAjax(iAmountLogService.updateById(amountLog) ? 1 : 0);
    }

    /**
     * 删除用户金额变化
     */
    @PreAuthorize("@ss.hasPermi('wx:amountLog:remove')" )
    @Log(title = "用户金额变化" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iAmountLogService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
